<%@page import="cn.school.mybaits.Server.GradeServer"%>
<%@page import="cn.school.mybaits.entity.Grade"%>
<%@page import="java.util.List"%>
<%@page import="cn.school.mybaits.Dao.GradeDao"%>
<%@page import="cn.school.mybaits.xml.MyBatisUtil"%>
<%@page import="org.apache.ibatis.session.SqlSession"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/new/js/jquery-3.2.1.min.js"></script>
</head>
<body>
	<h2>增加学生</h2>
	<div>
		<!-- <form action="AddStudent.jsp" method="post"> -->
		<form action="doAddStudent" method="post"
			enctype="multipart/form-data">
			<p>
				<input type="text" name="sname" placeholder="学生姓名">
			</p>
			<p>
				<input type="radio" name="sex" value="男" checked="checked">男
				<input type="radio" name="sex" value="女" />女
			</p>
			<p>
				<input type="text" name="telephone" placeholder="号码">
			</p>
			<p>
				<input type="text" name="qq" placeholder="QQ">
			</p>
			<p>
				<input type="text" name="wechat" id="name" placeholder="微信">
			</p>
			<p>
				年级id: <select name="gradeid">
					<c:forEach items="${list}" var="g">
						<option value="${g.id}">${g.gname}</option>
					</c:forEach>
				</select>
			</p>
			<p>
				<input type="text" name="enterdate" placeholder="入学日期">
			</p>
			<p>
				<input type="text" name="fromcity" placeholder="家乡">
			</p>
			<p>
				<input type="text" name="birthday" placeholder="生日">
			</p>
			<p>
				<input type="text" name="address" placeholder="地址">
			</p>
			<p>
				<input type="password" name="pass" placeholder="密码">
			</p>
			<p>
				<!-- onchange元素改变即触发 -->
				<input type="file" name="idcardpictrue"
					onchange="displayPicture(this)">
			</p>
			<img src="" id="selectImg" height="200px" width="400px">
			<p>
				<input type="submit" id="BtnAdd" value="提交">
			</p>
		</form>
	</div>
	<script>
		//设置事件
		function displayPicture(o) {
			var file = o.files[0];//获得文件路径		
			var reader = new FileReader();//创建文件读取对象
			reader.readAsDataURL(file);//读取文件
			reader.onload = function(e) { //成功读取文件,并加载
				var img = document.getElementById("selectImg");
				img.src = e.target.result; //将结果添加到img中src上
			};
		}
		$("#name").blur(function() {
			var wechat = this.value;
			if (wechat == "" || wechat == null) {
				alert("请填入微信号!");
			} else {
				var url = "checkWechatRequeat";
				$.ajax({
					"url" : url,
					"type" : "GET",
					"data" : "wechat" + wechat,
					"dateType" : "text",
					"success" : ifSuccess,
					"error" : function() {alert("验证出错!请重试");}
				});

				function ifSuccess(data) {
					if (data == "true") {
						alert("此微信号已注册!");
					} else {
						alert("此微信号可以使用!");
					}
				}
				alert(data);
			}
		});
	</script>
</body>
</html>